/*
 * ==========================================================================*\
 * | $Id: Window.java 360 2011-02-20 19:43:41Z vtwoods@gmail.com $
 * |*-------------------------------------------------------------------------*|
 * | Copyright (C) 2009 Virginia Tech | | This file is part of CloudSpace. | |
 * CloudSpace is free software; you can redistribute it and/or modify | it under
 * the terms of the GNU General Public License as published | by the Free
 * Software Foundation; either version 3 of the License, or | (at your option)
 * any later version. | | CloudSpace is distributed in the hope that it will be
 * useful, | but WITHOUT ANY WARRANTY; without even the implied warranty of |
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | GNU General
 * Public License for more details. | | You should have received a copy of the
 * GNU General Public License | along with CloudSpace; if not, see
 * <http://www.gnu.org/licenses/>.
 * \*==========================================================================
 */

package student.web;

import org.zkoss.zk.ui.Component;


// -------------------------------------------------------------------------
/**
 * A generic window.
 * 
 * <p>
 * This is a slightly enhanced subclass of {@link org.zkoss.zul.Window}. The
 * main change is that this version provides for a "smart" border property. An
 * org.zkoss.zul.Window defaults to having no border, all the time. This
 * subclass defaults to having no border if there is no title or caption, but
 * defaults to including a border if you provide a title or caption. As always,
 * this is just the default--if you specify a border property yourself, that
 * setting is always respected.
 * </p>
 * <p>
 * See {@link org.zkoss.zul.Window} for the real details on using Windows.
 * </p>
 * 
 * @author Stephen Edwards
 * @author Last changed by $Author: vtwoods@gmail.com $
 * @version $Revision: 360 $, $Date: 2010-11-17 22:10:44 -0500 (Wed, 17 Nov
 *          2010) $
 */
public class Window extends org.zkoss.zul.Window
{
    // ~ Constructors ..........................................................

    /**
	 * 
	 */
    private static final long serialVersionUID = 6741417824116471265L;


    // ----------------------------------------------------------
    /**
     * Creates a new Window object.
     */
    public Window()
    {
        super();
    }


    // ----------------------------------------------------------
    /**
     * Creates a new Window object.
     * 
     * @param title
     *            the window title (see {@link #setTitle}).
     * @param border
     *            the border (see {@link #setBorder}).
     * @param closable
     *            whether it is closable (see {@link #setClosable}).
     */
    public Window( String title, String border, boolean closable )
    {
        super( title, border, closable );
    }


    // ~ Public methods ........................................................

    // ----------------------------------------------------------
    /**
     * Sets the border (either "none" or "normal").
     * 
     * @param border
     *            the border. If null or "0", "none" is assumed.
     */
    @Override
    public void setBorder( String border )
    {
        hasBorderSetting = true;
        super.setBorder( border );
    }


    // ----------------------------------------------------------
    /**
     * Sets the title.
     * 
     * @param title
     *            the new title
     */
    @Override
    public void setTitle( String title )
    {
        super.setTitle( title );
        preferToHaveBorder();
    }


    // ----------------------------------------------------------
    /**
     * Inserts a child before the reference child.
     * 
     * <p>
     * You could use {@link Component#setParent} or
     * {@link Component#appendChild} instead of this method, unless you want to
     * control where to put the child.
     * 
     * @param newChild
     *            the new child to be inserted.
     * @param refChild
     *            the child before which you want the new child being inserted.
     *            If null, the new child is append to the end.
     * @return true if newChild is added successfully or moved; false if it
     *         already has the specified child and the order doesn't change.
     */
    @Override
    public boolean insertBefore( Component newChild, Component refChild )
    {
        if ( newChild instanceof org.zkoss.zul.Caption )
        {
            preferToHaveBorder();
        }
        return super.insertBefore( newChild, refChild );
    }


    // ~ Private methods .......................................................

    // ----------------------------------------------------------
    private void preferToHaveBorder()
    {
        if ( !hasBorderSetting )
        {
            setBorder( "normal" );
        }
    }

    // ~ Instance/static variables .............................................

    private transient boolean hasBorderSetting = false;
}
